home *** CD-ROM | disk | FTP | other *** search
/ All for Cell Phones: Sony Ericsson / Sony-Ericsson 2004.iso / Java / Excel / Sheet.jar / sheet / SheetShow.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-09-03  |  9.7 KB  |  371 lines

  1. package sheet;
  2.  
  3. import javax.microedition.lcdui.Alert;
  4. import javax.microedition.lcdui.AlertType;
  5. import javax.microedition.lcdui.Canvas;
  6. import javax.microedition.lcdui.Command;
  7. import javax.microedition.lcdui.CommandListener;
  8. import javax.microedition.lcdui.Display;
  9. import javax.microedition.lcdui.Displayable;
  10. import javax.microedition.lcdui.Font;
  11. import javax.microedition.lcdui.Form;
  12. import javax.microedition.lcdui.Graphics;
  13. import javax.microedition.lcdui.Image;
  14. import javax.microedition.lcdui.List;
  15. import javax.microedition.lcdui.StringItem;
  16. import javax.microedition.lcdui.TextBox;
  17.  
  18. final class SheetShow extends Canvas implements CommandListener, Backable {
  19.    private static final short TBL_WIDTH = 10;
  20.    private static final short TBL_HEIGHT = 9;
  21.    private static final short M_CELL_DATA = 0;
  22.    private static final short M_CELL_FORMAT = 1;
  23.    private static final short M_RECALC = 2;
  24.    private static final short M_FILE = 3;
  25.    private static final short M_CANCEL = 4;
  26.    private static final short M_HELP = 5;
  27.    private static final short M_E_COLOUR = 6;
  28.    private static final short M_E_ALIGN = 7;
  29.    private static final short MCD_EDIT = 0;
  30.    private static final short MCD_CLEAR = 1;
  31.    private static final short MCD_COPY = 2;
  32.    private static final short MCD_PASTE = 3;
  33.    private static final short MCD_BACK = 4;
  34.    private static final short MCF_SIZE = 0;
  35.    private static final short MCF_COLOUR = 1;
  36.    private static final short MCF_ALIGN = 2;
  37.    private static final short MCF_BACK = 3;
  38.    private static final short MFM_NEW = 0;
  39.    private static final short MFM_LOAD = 1;
  40.    private static final short MFM_SAVE = 2;
  41.    private static final short MFM_EXIT = 3;
  42.    private static final short MFM_BACK = 4;
  43.    private static final Command[] COMMANDS = new Command[]{new Command("Cell Data", 1, 0), new Command("Cell Format", 1, 1), new Command("Recalculate", 1, 2), new Command("File", 1, 3), new Command("Cancel", 3, 4), new Command("Help", 5, 5)};
  44.    private static final List[] MENUS = new List[]{new List("Cell Data", 3, new String[]{"Edit Cell", "Clear Cell", "Copy", "Paste", "Back to sheet"}, (Image[])null), new List("Cell Format", 3, new String[]{"Cell Size", "Cell Colour", "Cell Alignment", "Back to sheet"}, (Image[])null), null, new List("File", 3, new String[]{"New sheet", "Open", "Save", "Exit", "Back to sheet"}, (Image[])null), null, null};
  45.    private static final Command okCommand = new Command("Ok", 4, 1);
  46.    private static final Command cancelCommand = new Command("Cancel", 3, 1);
  47.    private static int appWidth;
  48.    private static int appHeight;
  49.    private static Display display;
  50.    private static Quitable winQuit;
  51.    private Table data;
  52.    private Cell clipBoard;
  53.    private boolean moved;
  54.  
  55.    public SheetShow() {
  56.       for(int var1 = 0; var1 < COMMANDS.length; ++var1) {
  57.          ((Displayable)this).addCommand(COMMANDS[var1]);
  58.       }
  59.  
  60.       appWidth = ((Canvas)this).getWidth();
  61.       appHeight = ((Canvas)this).getHeight();
  62.       this.data = this.newSheet();
  63.       this.moved = true;
  64.  
  65.       try {
  66.          Class.forName("sheet.Cell");
  67.          Class.forName("sheet.Operation");
  68.          Class.forName("sheet.CellCalc");
  69.          Class.forName("sheet.CellCalc$IntegerStack");
  70.       } catch (ClassNotFoundException var3) {
  71.       }
  72.  
  73.    }
  74.  
  75.    public void show(Display var1, Quitable var2) {
  76.       winQuit = var2;
  77.       display = var1;
  78.       this.show();
  79.    }
  80.  
  81.    public void show() {
  82.       display.setCurrent(this);
  83.       ((Displayable)this).setCommandListener(this);
  84.    }
  85.  
  86.    protected void paint(Graphics var1) {
  87.       var1.setColor(16777215);
  88.       var1.fillRect(0, 0, appWidth, appHeight);
  89.       this.data.paint(var1, appWidth, appHeight, 0);
  90.    }
  91.  
  92.    private void actualSave(String var1) {
  93.       try {
  94.          this.data.save(var1);
  95.          this.show();
  96.       } catch (IllegalArgumentException var4) {
  97.          Alert var3 = new Alert("File error", ((Throwable)var4).getMessage(), (Image)null, AlertType.ERROR);
  98.          display.setCurrent(var3, this);
  99.       }
  100.  
  101.    }
  102.  
  103.    private void actualLoad(String var1) {
  104.       try {
  105.          Table var2 = Table.load(var1);
  106.          this.data = var2;
  107.          if (this.data != null) {
  108.             this.data.calculate();
  109.          }
  110.  
  111.          this.show();
  112.       } catch (IllegalArgumentException var4) {
  113.          Alert var3 = new Alert("File error", ((Throwable)var4).getMessage(), (Image)null, AlertType.ERROR);
  114.          display.setCurrent(var3, this);
  115.       }
  116.  
  117.    }
  118.  
  119.    private void showWait(String var1, Runnable var2) {
  120.       1 var3 = new 1(this, var1, var2);
  121.       display.setCurrent(var3);
  122.    }
  123.  
  124.    private void save(Runnable var1) {
  125.       TextBox var2 = new TextBox("Enter sheet name", this.data.getName(), 32, 4);
  126.       ((Displayable)var2).setCommandListener(new 2(this, var1));
  127.       ((Displayable)var2).addCommand(okCommand);
  128.       ((Displayable)var2).addCommand(cancelCommand);
  129.       display.setCurrent(var2);
  130.    }
  131.  
  132.    private void load() {
  133.       this.showWait("Reading...", new 4(this, this));
  134.    }
  135.  
  136.    private void checkModified(Runnable var1) {
  137.       if (this.data.isChanged()) {
  138.          Command var2 = new Command("Yes", 1, 1);
  139.          Command var3 = new Command("No", 1, 1);
  140.          Form var4 = new Form("Warning");
  141.          var4.append(new StringItem((String)null, "The data was modified. Save?"));
  142.          ((Displayable)var4).setCommandListener(new 8(this, var2, var1, var3));
  143.          ((Displayable)var4).addCommand(var2);
  144.          ((Displayable)var4).addCommand(var3);
  145.          ((Displayable)var4).addCommand(cancelCommand);
  146.          display.setCurrent(var4);
  147.       } else {
  148.          var1.run();
  149.       }
  150.  
  151.    }
  152.  
  153.    public void keyPressed(int var1) {
  154.       int var2 = ((Canvas)this).getGameAction(var1);
  155.       switch (var2) {
  156.          case 1:
  157.             this.data.moveCursor(1);
  158.             this.moved = true;
  159.             break;
  160.          case 2:
  161.             this.data.moveCursor(3);
  162.             this.moved = true;
  163.             break;
  164.          case 3:
  165.          case 4:
  166.          case 7:
  167.          default:
  168.             if (var1 == -12) {
  169.                this.menuAction((short)3, (short)3);
  170.                this.moved = true;
  171.             } else if (var1 == 35) {
  172.                this.data.getCurrentCell(true).edit((String)null, this, display);
  173.             } else if (var1 == 42 && this.moved) {
  174.                var1 = 61;
  175.                this.data.getCurrentCell(true).edit(String.valueOf((char)var1), this, display);
  176.                this.data.moveCursor(2);
  177.             } else {
  178.                if (var1 == 42) {
  179.                   var1 = 8;
  180.                }
  181.  
  182.                this.moved = !this.data.getCurrentCell(true).appendChar((char)var1, this.moved);
  183.             }
  184.             break;
  185.          case 5:
  186.             this.data.moveCursor(4);
  187.             this.moved = true;
  188.             break;
  189.          case 6:
  190.             this.data.moveCursor(2);
  191.             this.moved = true;
  192.             break;
  193.          case 8:
  194.             Cell var3 = this.data.getCurrentCell(false);
  195.             Alert var4;
  196.             if (var3 != null) {
  197.                var4 = new Alert(var3.getName() + " details", var3.getDetails(), (Image)null, (AlertType)null);
  198.             } else {
  199.                var4 = new Alert("Details", "This cell is empty", (Image)null, (AlertType)null);
  200.             }
  201.  
  202.             this.moved = true;
  203.             var4.setTimeout(-2);
  204.             display.setCurrent(var4, this);
  205.       }
  206.  
  207.       ((Canvas)this).repaint();
  208.    }
  209.  
  210.    private void setSubmenu(Displayable var1, short var2) {
  211.       var1.setCommandListener(new 9(this, this, var2));
  212.    }
  213.  
  214.    public void commandAction(Command var1, Displayable var2) {
  215.       short var3 = (short)var1.getPriority();
  216.       this.moved = true;
  217.       if (MENUS[var3] != null) {
  218.          this.setSubmenu(MENUS[var3], var3);
  219.          display.setCurrent(MENUS[var3]);
  220.       } else {
  221.          this.menuAction(var3, (short)0);
  222.       }
  223.  
  224.    }
  225.  
  226.    private Table newSheet() {
  227.       Font var1 = Font.getFont(64, 0, 8);
  228.       short var2 = (short)var1.stringWidth("0000");
  229.       short var3 = (short)(var1.getHeight() + 1);
  230.       this.clipBoard = null;
  231.       return new Table((short)10, (short)9, var2, var3);
  232.    }
  233.  
  234.    public void menuAction(short var1, short var2) {
  235.       switch (var1) {
  236.          case 0:
  237.             switch (var2) {
  238.                case 0:
  239.                   this.data.getCurrentCell(true).edit((String)null, this, display);
  240.                   return;
  241.                case 1:
  242.                   this.data.clearCurrentCell();
  243.                   this.show();
  244.                   return;
  245.                case 2:
  246.                   this.clipBoard = this.data.getCurrentCell(false);
  247.                   this.show();
  248.                   return;
  249.                case 3:
  250.                   if (this.clipBoard != null) {
  251.                      this.data.getCurrentCell(true).paste(this.clipBoard);
  252.                   }
  253.                case 4:
  254.                   this.show();
  255.                   return;
  256.                default:
  257.                   return;
  258.             }
  259.          case 1:
  260.             switch (var2) {
  261.                case 0:
  262.                   CellResize var4 = new CellResize(this.data, this);
  263.                   display.setCurrent(var4);
  264.                   return;
  265.                case 1:
  266.                   List var6 = new List("Cell Colour", 3, Cell.colors, (Image[])null);
  267.                   this.setSubmenu(var6, (short)6);
  268.                   display.setCurrent(var6);
  269.                   return;
  270.                case 2:
  271.                   List var3 = new List("Cell Alignment", 3, Cell.aligns, (Image[])null);
  272.                   this.setSubmenu(var3, (short)7);
  273.                   display.setCurrent(var3);
  274.                   return;
  275.                case 3:
  276.                   this.show();
  277.                   return;
  278.                default:
  279.                   return;
  280.             }
  281.          case 2:
  282.             this.showWait("Calculating...", new 10(this));
  283.             break;
  284.          case 3:
  285.             switch (var2) {
  286.                case 0:
  287.                   this.checkModified(new 11(this));
  288.                   return;
  289.                case 1:
  290.                   this.checkModified(new 12(this));
  291.                   return;
  292.                case 2:
  293.                   this.save((Runnable)null);
  294.                   return;
  295.                case 3:
  296.                   this.checkModified(new 13(this));
  297.                   return;
  298.                case 4:
  299.                   this.show();
  300.                   return;
  301.                default:
  302.                   return;
  303.             }
  304.          case 4:
  305.             this.show();
  306.             break;
  307.          case 5:
  308.             Alert var5 = new Alert("Sheet help", "This is a small spreadsheet application capable of simple integer and string operations. You can find some hints in the Formula help (accessible from the formula editor).\n- To enter a numeric value, simply type the number ('*' serves as a backspace).\n- To enter a formula, press '*' key, then the formula editor will be opened with '=' pre-entered.\n- To simply edit a cell formula, press '#'.\n- Left softkey shows the full cell data.\n---\nMC, 2001", (Image)null, (AlertType)null);
  309.             var5.setTimeout(-2);
  310.             display.setCurrent(var5, this);
  311.             break;
  312.          case 6:
  313.             this.data.getCurrentCell(true).setColor(var2);
  314.             this.show();
  315.             break;
  316.          case 7:
  317.             this.data.getCurrentCell(true).setAlign(var2);
  318.             this.show();
  319.       }
  320.  
  321.    }
  322.  
  323.    static Display access$000() {
  324.       return display;
  325.    }
  326.  
  327.    static Command access$100() {
  328.       return okCommand;
  329.    }
  330.  
  331.    static void access$300(SheetShow var0, String var1) {
  332.       var0.actualSave(var1);
  333.    }
  334.  
  335.    static void access$500(SheetShow var0, String var1, Runnable var2) {
  336.       var0.showWait(var1, var2);
  337.    }
  338.  
  339.    static void access$800(SheetShow var0, String var1) {
  340.       var0.actualLoad(var1);
  341.    }
  342.  
  343.    static Command access$1100() {
  344.       return cancelCommand;
  345.    }
  346.  
  347.    static void access$1200(SheetShow var0, Runnable var1) {
  348.       var0.save(var1);
  349.    }
  350.  
  351.    static Table access$1300(SheetShow var0) {
  352.       return var0.data;
  353.    }
  354.  
  355.    static Table access$1302(SheetShow var0, Table var1) {
  356.       return var0.data = var1;
  357.    }
  358.  
  359.    static Table access$1400(SheetShow var0) {
  360.       return var0.newSheet();
  361.    }
  362.  
  363.    static void access$1500(SheetShow var0) {
  364.       var0.load();
  365.    }
  366.  
  367.    static Quitable access$1600() {
  368.       return winQuit;
  369.    }
  370. }
  371.